package com.xzy.generic.bad.example.c;

import lombok.Getter;
import lombok.ToString;
import org.springframework.context.ApplicationEvent;
import org.springframework.core.ResolvableType;
import org.springframework.core.ResolvableTypeProvider;

/**
 * 自定义事件
 *
 * @author xzy.xiao
 * @date 2022/10/8  18:57
 */
@Getter
@ToString
//public class GenericEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {
public class GenericEvent<T> extends ApplicationEvent implements ResolvableTypeProvider {


    /**
     * 事件类型
     */
    private final OperationType eventType;
    /**
     * 相关数据
     */
    private final T eventData;


    public GenericEvent(Object source, OperationType eventType, T eventData) {
        super(source);
        this.eventType = eventType;
        this.eventData = eventData;
    }

    /**
     * Return the {@link ResolvableType} describing this instance
     * (or {@code null} if some sort of default should be applied instead).
     */
    @Override
    public ResolvableType getResolvableType() {
        return ResolvableType.forClassWithGenerics(
                this.getClass(),
                ResolvableType.forClass(this.eventData.getClass())
        );
    }
}
